<template>
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px;width: 100%;"
  >
    <el-col>
      <!-- 样式属性名 fontWeight或者'font-weight' -->
      <span :style="{fontWeight:isCompany?'700':''}">{{ nodeTree.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ nodeTree.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown>
            <span> 操作<i class="el-icon-arrow-down" /> </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addFn">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="isCompany===false" @click.native="editFn">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!isCompany" @click.native="delFn">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
export default {
  props: {
    nodeTree: {
      type: Object,
      required: true
    },
    isCompany: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    // 新增部门
    addFn() {
      // 子传父,把点击按钮所在的部门ID传递给父组件，然后保存起来
      this.$emit('addEvent', this.nodeTree.id)
    },
    // 删除部门
    delFn() {
      this.$emit('delEvent', this.nodeTree.id)
    },
    // 编辑部门
    editFn() {
      this.$emit('editEvent', this.nodeTree.id)
    }
  }
}
</script>
